[1,2,3].each { |n| puts n*n }
1 4 9
[1, 2, 3]
require "daru"
df = Daru::DataFrame.new(
island: ["Mêlée_Island", "Plunder Island", "Monkey Island"],
monkey_population: [776, 166, 1329],
size: [1, 10, 3]
)
| island | monkey_population | size | |
|---|---|---|---|
| 0 | Mêlée_Island | 776 | 1 |
| 1 | Plunder Island | 166 | 10 |
| 2 | Monkey Island | 1329 | 3 |
# Choose columns
df[:island]
| island | |
|---|---|
| 0 | Mêlée_Island |
| 1 | Plunder Island |
| 2 | Monkey Island |
# Sophisticated filtering
df.where(df[:size] > 1)
df.where(df[:island].eq("Plunder Island") | (df[:monkey_population] < 1000))
| island | monkey_population | size | |
|---|---|---|---|
| 0 | Mêlée_Island | 776 | 1 |
| 1 | Plunder Island | 166 | 10 |
owners = Daru::DataFrame.new(
name: ["Bob", "Alice", "Julie"], pet_id: [1, 2, 2]
)
pets = Daru::DataFrame.new(
name: ["Suzy", "Manfred", "George"],
pet_id: [1, 2, 3],
type: ["cat", "dinosaur", "dog"]
)
| name | pet_id | type | |
|---|---|---|---|
| 0 | Suzy | 1 | cat |
| 1 | Manfred | 2 | dinosaur |
| 2 | George | 3 | dog |
# You can join them together!
require "iruby/chartkick"
include IRuby::Chartkick
data = JobOffer.group_by_day(:created_at).size
bar_chart(data, points: false, max: 5)